
package common.packet;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * General purpose error packet.
 *
 * @author xissburg
 */
public class Error implements Packet
{
    private String message;

    public Error() {
        this("");
    }

    public Error(String message) {
        this.message = message;
    }

    public Error(DataInputStream in) throws IOException
    {
        this();
        read(in);
    }

    public Error(Error error) {
        this(error.getMessage());
    }

    public void read(DataInputStream in) throws IOException
    {
        message = in.readUTF();
    }

    public void write(DataOutputStream out) throws IOException {
        out.writeUTF(getCode().name());
        out.writeUTF(message);
    }

    public Code getCode() {
        return Code.ERROR;
    }

    public Error copy() {
        return new Error(this);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
